$(document).ready(function() {
    var dataSource = new kendo.data.DataSource({
        transport: {
            create: {
                url: appBosch.crud.create,
                dataType: "json"
            },
            read: {
                url: appBosch.crud.read,
                dataType: "json"
            },
            update: {
                url: appBosch.crud.update,
                dataType: "json"
            },
            destroy: {
                url: appBosch.crud.destroy,
                dataType: "json"
            },
            parameterMap: function(options, operation) {
                var params = {};
                switch (operation)
                {
                    case 'create':
                        params = {models: kendo.stringify(options.models)};
                        break;
                    case 'read':
                        break;
                    case 'update':
                        params = {models: kendo.stringify(options.models)};
                        break;
                    case 'destroy':
                        params = {id: options.models[0].id};
                        break;
                }
                return params;
            }
        },
        batch: true,
        schema: {
            model: {
                id: "id",
                fields: {
                    test_id: {
                        editable: true,
                        nullable: false,
                        defaultValue: appBosch.tests[0].value
                    },
                    user_name: {
                        editable: false,
                        nullable: false
                    },
                    location: {
                        editable: true,
                        nullable: false,
                        validation: {
                            required: true
                        }
                    },
                    test_date: {
                        type: "date",
                        editable: true,
                        nullable: false,
                        validation: {
                            required: true
                        }
                    }
                }
            }
        }
    });

    $("#grid").kendoGrid({
        scrollable: true,
        filterable: true,
        selectable: true,
        navigatable: true,
        sortable: {
            mode: "single",
            allowUnsort: false
        },
        pageable: true,
        dataSource: dataSource,
        height: 520,
        toolbar: ['create'],
        columns: [
            {field: "test_id", title: "Curso", values: appBosch.tests},
            {field: "user_name", title: "Creado por"},
            {field: "test_date", title: "Fecha y hora", template: "#= kendo.toString(test_date, 'F') #"},
            {field: "location", title: "Lugar"},
            {command: [
                    {
                        name: "edit",
                        text: {
                            edit: "",
                            update: "",
                            cancel: ""
                        }
                    },
                    {
                        name: "destroy",
                        text: ""
                    }], title: "&nbsp;"}],
        editable: {
            confirmation: "¿Estas seguro que deseas eliminar esta programación de Entrenamiento?",
            mode: "popup"
        }
    });
});